Calculating Pi

Here’s a port of the infamous PI.TEC by Stanley Rabinowitz according to “A Spigot Algorithm for the Digits of Pi”, American Mathematical Monthly 102 (1995) 195-203. It only required some minor changes like replacing B with 0, adding braces due to SciTECO’s operator precedence and discarding values at the end of If-statements. I have also adapted the “coding style” to be closer to other SciTECO macros, although this was entirely optional.

\Un Qn"= 20Un ' 0Uh 0Uv HK
Qn< J 0Uq Qn*10/3Ui
Qi< (\+2)*10+(Qq*Qi)Ua 0L :K$ Qi*2-1Uj Qa/QjUq
Qa-(Qq*Qj)-2\ 10@I// -%i >
Qq/10Ut Qh+Qt+48Uw Qw-58"= 48Uw %v$ ' Qv"N Qv^T ' QwUv Qq-(Qt*10)Uh >
Qv^T @^A/
/-EX

It can be called with sciteco -qm pi.tec <n>, whereas n is the number of digits to calculate (20 by default).


14B	Sep 28 21:20 ../